package com.tarena.lbs.basic.service.impl;

import com.tarena.lbs.basic.dao.repository.AreaRepository;
import com.tarena.lbs.basic.pojo.po.AreaPO;
import com.tarena.lbs.basic.pojo.vo.AreaVO;
import com.tarena.lbs.basic.service.AreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
@Slf4j
public class AreaServiceImpl implements AreaService {
    @Autowired
    private AreaRepository areaRepository;

    @Override
    public List<AreaVO> queryProvinces() {
        List<AreaVO> cities = areaRepository.queryProvinces(2);
            // 查询每个市的区
            for (AreaVO city : cities) {// 这里的 city.getId() 是每个市的 ID
                List<AreaVO> regions = areaRepository.queryProvincesByParentId(city.getId());// 这里的 city.getId() 是每个市的 ID
                city.setChildren(regions);
                log.info("查询每个市的区：{}",regions);
            }
      return cities;
    }

    @Override
    public List<AreaVO> selectChildren(Long parentId) {
        List<AreaVO> cities = areaRepository.queryProvincesByParentId(parentId);
        return cities;
    }

    @Override
    public List<AreaVO> selectProvinces() {
        List<AreaVO> provinces = areaRepository.queryProvinces(1);
        return provinces;
    }


}
